
package com.applabs.mydiary;

import com.applabs.mydiary.core.DbPersister;
import com.applabs.mydiary.core.DiaryEvent;
import com.applabs.mydiary.core.IPersister;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class MyDiaryMain extends Activity {
    IPersister dbPersister = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_diary_main);
        testData();
        List<DiaryEvent> listEvents = dbPersister.getAllEvents();
        for (int i = 0; i < listEvents.size(); i++) {
            Log.d("MyDiary: ", i + "-> " + listEvents.get(i));
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my_diary_main, menu);
        return true;
    }

    public void testData() {
        DiaryEvent event = new DiaryEvent();
        dbPersister = DbPersister.getInstance(getApplicationContext());
        event.setStartTime(getCurrentTimeStamp());
        event.setEndTime(getCurrentTimeStamp());
        event.setEventDate(new Date().toString());
        event.setLongitude(0);
        event.setLatitude(0);
        event.setNotes("Testing");
        event.setAddress("Neshanic St, NJ");
        dbPersister.addEvent(event);
    }

    public static String getCurrentTimeStamp() {
        SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// dd/MM/yyyy
        Date now = new Date();
        String strDate = sdfDate.format(now);
        return strDate;
    }

}
